home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12601 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Settle a bet please
  5. Date: 1 Apr 1996 21:00:32 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4jpg5g$6i@sparcserver.lrz-muenchen.de>
  9. References: <4jfopb$o9n@news1.sympatico.ca> <4jh8rtINNosd@mayne.ugrad.cs.ubc.ca> <4jp8li$ue@eri2.erinet.com>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. timb@erinet.com (Tim Berens) writes:
  13.  
  14. >Here's an interesting way to decide for yourselves:
  15.  
  16. >main()
  17. >{
  18. >    printf("size is: %d",sizeof("My Name"));
  19. >}
  20.  
  21. >This will display how many bytes your compiler thinks should be
  22. >allocated for "My Name"
  23.  
  24. If size_t is defined as int (which it cannot be, because it is an
  25. unsigned quantity) this will always work. However, if you have to
  26. print something, and all you can possibly know about it is that it
  27. is an unsigned integer type, it might be better to cast it to and
  28. print it as a type that can hold all values of unsigned integer 
  29. types:
  30.  
  31.      printf("size is %lu\n", (unsigned long) sizeof("My Name"));
  32.  
  33. Kurt
  34. --
  35. | Kurt Watzka                             Phone : +49-89-2180-6254
  36. | watzka@stat.uni-muenchen.de
  37.  
  38.